function saveStorage(id){ var data = document.getElementById(id).value; var time = new Date().getTime(); localStorage.setItem(time,data); alert("数据已经保存!"); loadStorage('msg'); } function loadStorage(id){ var result = '<table border = "1">'; for(var i = 0;i < localStorage.length;i++){ var key = localStorage.key(i); var value = localStorage.getItem(key); var date = new Date(); date.setTime(key); var datestr = date.toGMTString(); result += '<tr><td>' + value + '</td><td>' + datestr + '</td></tr>'; } result += '</table>'; var target = document.getElementById(id); target.innerHTML = result; } function clearStorage(){ localStorage.clear(); alert("全部数据被清除!"); loadStorage('msg'); }
function saveStorage(){ var data = new Object; data.name = document.getElementById('name').value; data.email = document.getElementById('email').value; data.tel = document.getElementById('tel').value; data.memo = document.getElementById('memo').value; var str = JSON.stringify(data); localStorage.setItem(data.name,str); alert("数据已经保存!"); } function findStorage(id){ var find = document.getElementById('find').value; var str = localStorage.getItem(find); var data = JSON.parse(str); var result = "姓名:" + data.name + '<br>'; result += "EMAIL:" + data.email + '<br>'; result += "电话号码:" + data.tel + '<br>'; result += "备注:" + data.memo + '<br>'; var target = document.getElementById(id); target.innerHTML = result; }